package com.minimalist.lindi.mapper;

import com.minimalist.common.entity.lindi.po.LindiSubsidyApplicationFile;
import com.minimalist.common.entity.lindi.vo.subsidyapplicationfile.LindiSubsidyApplicationFileQueryVO;
import com.mybatisflex.core.BaseMapper;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryChain;
import com.mybatisflex.core.query.QueryWrapper;

import java.util.List;

/**
 * 林地指标交易平台_补贴申请文件表 映射层。
 *
 * @author 11987
 * @since 2025-06-09
 */
public interface LindiSubsidyApplicationFileMapper extends BaseMapper<LindiSubsidyApplicationFile>{

    /**
     * 根据补贴申请ID查询文件列表
     *
     * @param subsidyApplicationId 补贴申请ID
     * @return 文件列表
     */
    default List<LindiSubsidyApplicationFile> selectFileListBySubsidyApplicationId(Long subsidyApplicationId){
        return selectListByQuery(QueryChain.create()
                .eq(LindiSubsidyApplicationFile::getSubsidyApplicationId, subsidyApplicationId)
                .orderBy(LindiSubsidyApplicationFile::getCreateTime, false));
    }

    /**
     * 根据文件ID查询补贴申请文件
     *
     * @param fileId 文件ID
     * @return 补贴申请文件
     */
    default LindiSubsidyApplicationFile selectSubsidyApplicationFileByFileId(Long fileId){
        return selectOneByQuery(QueryChain.create().eq(LindiSubsidyApplicationFile::getFileId, fileId));
    }

    /**
     * 根据文件类型查询补贴申请文件列表
     *
     * @param subsidyApplicationId 补贴申请ID
     * @param fileType             文件类型
     * @return 文件列表
     */
    default List<LindiSubsidyApplicationFile> selectFileListBySubsidyApplicationIdAndFileType(
            Long subsidyApplicationId, String fileType){
        return selectListByQuery(QueryChain.create()
                .eq(LindiSubsidyApplicationFile::getSubsidyApplicationId, subsidyApplicationId)
                .eq(LindiSubsidyApplicationFile::getFileType, fileType)
                .orderBy(LindiSubsidyApplicationFile::getCreateTime, false));
    }

    /**
     * 分页查询补贴申请文件列表
     *
     * @param queryVO 查询条件
     * @return 分页结果
     */
    default Page<LindiSubsidyApplicationFile> selectPageSubsidyApplicationFileList(LindiSubsidyApplicationFileQueryVO queryVO){
        return paginate(queryVO.getPageNum(), queryVO.getPageSize(),
                QueryWrapper.create()
                        .eq(LindiSubsidyApplicationFile::getSubsidyApplicationId, queryVO.getSubsidyApplicationId())
                        .eq(LindiSubsidyApplicationFile::getFileType, queryVO.getFileType())
                        .eq(LindiSubsidyApplicationFile::getFileId, queryVO.getFileId())
                        .orderBy(LindiSubsidyApplicationFile::getCreateTime, false));
    }

    /**
     * 根据补贴申请ID删除所有文件
     *
     * @param subsidyApplicationId 补贴申请ID
     * @return 删除数量
     */
    default int deleteBySubsidyApplicationId(Long subsidyApplicationId){
        return deleteByQuery(QueryChain.create()
                .eq(LindiSubsidyApplicationFile::getSubsidyApplicationId, subsidyApplicationId));
    }

    /**
     * 根据文件ID删除补贴申请文件
     *
     * @param fileId 文件ID
     * @return 删除数量
     */
    default void deleteByFileId(Long fileId){
        deleteByQuery(QueryWrapper.create()
                .eq(LindiSubsidyApplicationFile::getFileId, fileId));
    }

    /**
     * 根据补贴申请ID和文件类型删除补贴申请文件
     *
     * @param subsidyApplicationId 补贴申请ID
     * @param fileType             文件类型
     */
    default void deleteBySubsidyApplicationIdAndFileType(Long subsidyApplicationId, String fileType){
        deleteByQuery(QueryWrapper.create()
                .eq(LindiSubsidyApplicationFile::getSubsidyApplicationId
                        , subsidyApplicationId)
                .eq(LindiSubsidyApplicationFile::getFileType, fileType));
    }
}